package com.google.android.exoplayer2.mediacodec;

import android.annotation.TargetApi;
import android.media.MediaCodec;
import android.media.MediaCodec.BufferInfo;
import android.media.MediaCodec.CodecException;
import android.media.MediaCodec.CryptoInfo;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.os.Bundle;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.CheckResult;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import o.aay;
import o.abk;
import o.acz;
import o.adf;
import o.adn;
import o.ahb;
import o.ahe;
import o.amm;
import o.amz;
import o.and;
import o.ann;
import o.anp;
import o.anr;

@TargetApi(16)
public abstract class MediaCodecRenderer extends aay {
    private static final byte[] ˎ = anr.ʼ("0000016742C00BDA259000000168CE0F13200000016588840DCE7118A0002FBF1C31C3275D78");
    private final abk ʻ;
    private MediaCodec ʻॱ;
    private final ann<Format> ʼ;
    private boolean ʼॱ;
    private final DecoderInputBuffer ʽ;
    @Nullable
    private DecoderInitializationException ʽॱ;
    @Nullable
    private ArrayDeque<ahe> ʾ;
    @Nullable
    private ahe ʿ;
    private int ˈ;
    private boolean ˉ;
    protected acz ˊ;
    private boolean ˊˊ;
    private boolean ˊˋ;
    private final BufferInfo ˊॱ;
    private boolean ˊᐝ;
    @Nullable
    private final adf<adn> ˋ;
    private boolean ˋˊ;
    private ByteBuffer[] ˋˋ;
    private final List<Long> ˋॱ;
    private boolean ˋᐝ;
    private boolean ˌ;
    private boolean ˍ;
    private boolean ˎˎ;
    private ByteBuffer ˎˏ;
    private final boolean ˏ;
    private int ˏˎ;
    private int ˏˏ;
    private Format ˏॱ;
    private long ˑ;
    private Format ͺ;
    private ByteBuffer[] ͺॱ;
    private int ـ;
    private final ahb ॱ;
    private boolean ॱʻ;
    private int ॱʼ;
    private boolean ॱʽ;
    private Format ॱˊ;
    private DrmSession<adn> ॱˋ;
    private DrmSession<adn> ॱˎ;
    private boolean ॱͺ;
    private final float ॱॱ;
    private float ॱᐝ;
    private final DecoderInputBuffer ᐝ;
    private boolean ᐝˊ;
    private boolean ᐝˋ;
    private float ᐝॱ;
    private boolean ᐝᐝ;
    private boolean ᐧ;
    private boolean ᐨ;

    public static class DecoderInitializationException extends Exception {
        public final String ˊ;
        public final boolean ˋ;
        public final String ˎ;
        @Nullable
        public final DecoderInitializationException ˏ;
        public final String ॱ;

        public DecoderInitializationException(Format format, Throwable th, boolean z, int i) {
            this("Decoder init failed: [" + i + "], " + format, th, format.ʽ, z, null, ˋ(i), null);
        }

        public DecoderInitializationException(Format format, Throwable th, boolean z, String str) {
            String ˏ;
            String str2 = "Decoder init failed: " + str + ", " + format;
            String str3 = format.ʽ;
            if (anr.ˋ >= 21) {
                ˏ = ˏ(th);
            } else {
                ˏ = null;
            }
            this(str2, th, str3, z, str, ˏ, null);
        }

        private DecoderInitializationException(String str, Throwable th, String str2, boolean z, @Nullable String str3, @Nullable String str4, @Nullable DecoderInitializationException decoderInitializationException) {
            super(str, th);
            this.ˊ = str2;
            this.ˋ = z;
            this.ˎ = str3;
            this.ॱ = str4;
            this.ˏ = decoderInitializationException;
        }

        @CheckResult
        private DecoderInitializationException ˎ(DecoderInitializationException decoderInitializationException) {
            return new DecoderInitializationException(getMessage(), getCause(), this.ˊ, this.ˋ, this.ˎ, this.ॱ, decoderInitializationException);
        }

        @TargetApi(21)
        private static String ˏ(Throwable th) {
            if (th instanceof CodecException) {
                return ((CodecException) th).getDiagnosticInfo();
            }
            return null;
        }

        private static String ˋ(int i) {
            return "com.google.android.exoplayer.MediaCodecTrackRenderer_" + (i < 0 ? "neg_" : "") + Math.abs(i);
        }
    }

    protected abstract void ˊ(ahe o_ahe, MediaCodec mediaCodec, Format format, MediaCrypto mediaCrypto, float f) throws DecoderQueryException;

    protected abstract boolean ˊ(long j, long j2, MediaCodec mediaCodec, ByteBuffer byteBuffer, int i, int i2, long j3, boolean z, Format format) throws ExoPlaybackException;

    protected abstract int ˋ(ahb o_ahb, adf<adn> o_adf_o_adn, Format format) throws DecoderQueryException;

    public MediaCodecRenderer(int i, ahb o_ahb, @Nullable adf<adn> o_adf_o_adn, boolean z, float f) {
        super(i);
        amm.ˏ(anr.ˋ >= 16);
        this.ॱ = (ahb) amm.ॱ(o_ahb);
        this.ˋ = o_adf_o_adn;
        this.ˏ = z;
        this.ॱॱ = f;
        this.ʽ = new DecoderInputBuffer(0);
        this.ᐝ = DecoderInputBuffer.ˋ();
        this.ʻ = new abk();
        this.ʼ = new ann();
        this.ˋॱ = new ArrayList();
        this.ˊॱ = new BufferInfo();
        this.ـ = 0;
        this.ॱʼ = 0;
        this.ॱᐝ = SizeModifier.STABLE_STATE_SCALE;
        this.ᐝॱ = 1.0f;
    }

    public final int ˏॱ() {
        return 8;
    }

    public final int ˎ(Format format) throws ExoPlaybackException {
        try {
            return ˋ(this.ॱ, this.ˋ, format);
        } catch (Exception e) {
            throw ExoPlaybackException.ˊ(e, ॱᐝ());
        }
    }

    protected List<ahe> ˏ(ahb o_ahb, Format format, boolean z) throws DecoderQueryException {
        return o_ahb.ˊ(format.ʽ, z);
    }

    protected final void ʼॱ() throws ExoPlaybackException {
        boolean z = false;
        if (this.ʻॱ == null && this.ॱˊ != null) {
            boolean ˏ;
            this.ॱˎ = this.ॱˋ;
            String str = this.ॱˊ.ʽ;
            MediaCrypto mediaCrypto = null;
            if (this.ॱˎ != null) {
                adn o_adn = (adn) this.ॱˎ.ʼ();
                if (o_adn != null) {
                    mediaCrypto = o_adn.ॱ();
                    ˏ = o_adn.ˏ(str);
                } else if (this.ॱˎ.ॱॱ() != null) {
                    ˏ = false;
                } else {
                    return;
                }
                if (ـ()) {
                    int ˋ = this.ॱˎ.ˋ();
                    if (ˋ == 1) {
                        throw ExoPlaybackException.ˊ(this.ॱˎ.ॱॱ(), ॱᐝ());
                    } else if (ˋ != 4) {
                        return;
                    }
                }
            }
            ˏ = false;
            try {
                if (ˊ(mediaCrypto, ˏ)) {
                    String str2 = this.ʿ.ˎ;
                    this.ˈ = ˏ(str2);
                    this.ˊᐝ = ˋ(str2);
                    this.ˉ = ˋ(str2, this.ॱˊ);
                    this.ˋˊ = ˎ(str2);
                    this.ˊˊ = ॱ(str2);
                    this.ˊˋ = ˊ(str2);
                    this.ˎˎ = ˎ(str2, this.ॱˊ);
                    if (ˊ(this.ʿ) || ˊˊ()) {
                        z = true;
                    }
                    this.ˋᐝ = z;
                    this.ˑ = ˊ() == 2 ? SystemClock.elapsedRealtime() + 1000 : -9223372036854775807L;
                    ˋᐝ();
                    ˋˋ();
                    this.ᐝᐝ = true;
                    acz o_acz = this.ˊ;
                    o_acz.ॱ++;
                }
            } catch (Exception e) {
                throw ExoPlaybackException.ˊ(e, ॱᐝ());
            }
        }
    }

    protected boolean ˏ(ahe o_ahe) {
        return true;
    }

    protected boolean ˊˊ() {
        return false;
    }

    @Nullable
    protected final Format ˏ(long j) {
        Format format = (Format) this.ʼ.ॱ(j);
        if (format != null) {
            this.ˏॱ = format;
        }
        return format;
    }

    protected final MediaCodec ˋˊ() {
        return this.ʻॱ;
    }

    @Nullable
    protected final ahe ˊᐝ() {
        return this.ʿ;
    }

    public void ˏ(boolean z) throws ExoPlaybackException {
        this.ˊ = new acz();
    }

    public void ˏ(long j, boolean z) throws ExoPlaybackException {
        this.ᐧ = false;
        this.ᐝˊ = false;
        if (this.ʻॱ != null) {
            ˉ();
        }
        this.ʼ.ˊ();
    }

    public final void ॱ(float f) throws ExoPlaybackException {
        this.ᐝॱ = f;
        ˎˏ();
    }

    public void ॱˎ() {
        this.ॱˊ = null;
        this.ʾ = null;
        try {
            ˊˋ();
            try {
                if (this.ॱˎ != null) {
                    this.ˋ.ˊ(this.ॱˎ);
                }
                try {
                    if (!(this.ॱˋ == null || this.ॱˋ == this.ॱˎ)) {
                        this.ˋ.ˊ(this.ॱˋ);
                    }
                    this.ॱˎ = null;
                    this.ॱˋ = null;
                } catch (Throwable th) {
                    this.ॱˎ = null;
                    this.ॱˋ = null;
                }
            } catch (Throwable th2) {
                this.ॱˎ = null;
                this.ॱˋ = null;
            }
        } catch (Throwable th3) {
            this.ॱˎ = null;
            this.ॱˋ = null;
        }
    }

    protected void ˊˋ() {
        this.ˑ = -9223372036854775807L;
        ˋᐝ();
        ˋˋ();
        this.ᐨ = false;
        this.ॱͺ = false;
        this.ˋॱ.clear();
        ʿ();
        this.ʿ = null;
        this.ॱʽ = false;
        this.ॱʻ = false;
        this.ˉ = false;
        this.ˋˊ = false;
        this.ˈ = 0;
        this.ˊᐝ = false;
        this.ˊˊ = false;
        this.ˎˎ = false;
        this.ˍ = false;
        this.ˌ = false;
        this.ˋᐝ = false;
        this.ᐝˋ = false;
        this.ـ = 0;
        this.ॱʼ = 0;
        this.ʼॱ = false;
        if (this.ʻॱ != null) {
            acz o_acz = this.ˊ;
            o_acz.ˊ++;
            try {
                this.ʻॱ.stop();
                try {
                    this.ʻॱ.release();
                    this.ʻॱ = null;
                    if (this.ॱˎ != null && this.ॱˋ != this.ॱˎ) {
                        try {
                            this.ˋ.ˊ(this.ॱˎ);
                        } finally {
                            this.ॱˎ = null;
                        }
                    }
                } catch (Throwable th) {
                    this.ʻॱ = null;
                    if (!(this.ॱˎ == null || this.ॱˋ == this.ॱˎ)) {
                        this.ˋ.ˊ(this.ॱˎ);
                    }
                } finally {
                    this.ॱˎ = null;
                }
            } catch (Throwable th2) {
                this.ʻॱ = null;
                if (!(this.ॱˎ == null || this.ॱˋ == this.ॱˎ)) {
                    try {
                        this.ˋ.ˊ(this.ॱˎ);
                    } finally {
                        this.ॱˎ = null;
                    }
                }
            } finally {
                this.ॱˎ = null;
            }
        }
    }

    public void ॱˊ() {
    }

    public void ͺ() {
    }

    public void ˊ(long j, long j2) throws ExoPlaybackException {
        if (this.ᐝˊ) {
            ʾ();
            return;
        }
        int ˊ;
        if (this.ॱˊ == null) {
            this.ᐝ.ˊ();
            ˊ = ˊ(this.ʻ, this.ᐝ, true);
            if (ˊ == -5) {
                ˊ(this.ʻ.ॱ);
            } else if (ˊ == -4) {
                amm.ˏ(this.ᐝ.ˏ());
                this.ᐧ = true;
                ˏˏ();
                return;
            } else {
                return;
            }
        }
        ʼॱ();
        if (this.ʻॱ != null) {
            anp.ॱ("drainAndFeed");
            do {
            } while (ˋ(j, j2));
            do {
            } while (ˎˎ());
            anp.ˎ();
        } else {
            acz o_acz = this.ˊ;
            o_acz.ˏ += ˎ(j);
            this.ᐝ.ˊ();
            ˊ = ˊ(this.ʻ, this.ᐝ, false);
            if (ˊ == -5) {
                ˊ(this.ʻ.ॱ);
            } else if (ˊ == -4) {
                amm.ˏ(this.ᐝ.ˏ());
                this.ᐧ = true;
                ˏˏ();
            }
        }
        this.ˊ.ॱ();
    }

    protected void ˉ() throws ExoPlaybackException {
        this.ˑ = -9223372036854775807L;
        ˋᐝ();
        ˋˋ();
        this.ᐝᐝ = true;
        this.ᐨ = false;
        this.ॱͺ = false;
        this.ˋॱ.clear();
        this.ˍ = false;
        this.ˌ = false;
        if (this.ˋˊ || (this.ˊˊ && this.ᐝˋ)) {
            ˊˋ();
            ʼॱ();
        } else if (this.ॱʼ != 0) {
            ˊˋ();
            ʼॱ();
        } else {
            this.ʻॱ.flush();
            this.ॱʻ = false;
        }
        if (this.ॱʽ && this.ॱˊ != null) {
            this.ـ = 1;
        }
    }

    private boolean ˊ(MediaCrypto mediaCrypto, boolean z) throws DecoderInitializationException {
        if (this.ʾ == null) {
            try {
                this.ʾ = new ArrayDeque(ˎ(z));
                this.ʽॱ = null;
            } catch (Throwable e) {
                throw new DecoderInitializationException(this.ॱˊ, e, z, -49998);
            }
        }
        if (this.ʾ.isEmpty()) {
            throw new DecoderInitializationException(this.ॱˊ, null, z, -49999);
        }
        do {
            ahe o_ahe = (ahe) this.ʾ.peekFirst();
            if (!ˏ(o_ahe)) {
                return false;
            }
            try {
                ˊ(o_ahe, mediaCrypto);
                return true;
            } catch (Throwable e2) {
                amz.ˋ("MediaCodecRenderer", "Failed to initialize decoder: " + o_ahe, e2);
                this.ʾ.removeFirst();
                DecoderInitializationException decoderInitializationException = new DecoderInitializationException(this.ॱˊ, e2, z, o_ahe.ˎ);
                if (this.ʽॱ == null) {
                    this.ʽॱ = decoderInitializationException;
                } else {
                    this.ʽॱ = this.ʽॱ.ˎ(decoderInitializationException);
                }
                if (this.ʾ.isEmpty()) {
                    throw this.ʽॱ;
                }
            }
        } while (this.ʾ.isEmpty());
        throw this.ʽॱ;
    }

    private List<ahe> ˎ(boolean z) throws DecoderQueryException {
        List<ahe> ˏ = ˏ(this.ॱ, this.ॱˊ, z);
        if (ˏ.isEmpty() && z) {
            ˏ = ˏ(this.ॱ, this.ॱˊ, false);
            if (!ˏ.isEmpty()) {
                amz.ˏ("MediaCodecRenderer", "Drm session requires secure decoder for " + this.ॱˊ.ʽ + ", but no secure decoder available. Trying to proceed with " + ˏ + ".");
            }
        }
        return ˏ;
    }

    private void ˊ(ahe o_ahe, MediaCrypto mediaCrypto) throws Exception {
        MediaCodec mediaCodec = null;
        String str = o_ahe.ˎ;
        ˎˏ();
        boolean z = this.ॱᐝ > this.ॱॱ;
        try {
            long elapsedRealtime = SystemClock.elapsedRealtime();
            anp.ॱ("createCodec:" + str);
            mediaCodec = MediaCodec.createByCodecName(str);
            anp.ˎ();
            anp.ॱ("configureCodec");
            ˊ(o_ahe, mediaCodec, this.ॱˊ, mediaCrypto, z ? this.ॱᐝ : SizeModifier.STABLE_STATE_SCALE);
            this.ʼॱ = z;
            anp.ˎ();
            anp.ॱ("startCodec");
            mediaCodec.start();
            anp.ˎ();
            long elapsedRealtime2 = SystemClock.elapsedRealtime();
            ॱ(mediaCodec);
            this.ʻॱ = mediaCodec;
            this.ʿ = o_ahe;
            ˎ(str, elapsedRealtime2, elapsedRealtime2 - elapsedRealtime);
        } catch (Exception e) {
            if (mediaCodec != null) {
                ʿ();
                mediaCodec.release();
            }
            throw e;
        }
    }

    private void ॱ(MediaCodec mediaCodec) {
        if (anr.ˋ < 21) {
            this.ˋˋ = mediaCodec.getInputBuffers();
            this.ͺॱ = mediaCodec.getOutputBuffers();
        }
    }

    private void ʿ() {
        if (anr.ˋ < 21) {
            this.ˋˋ = null;
            this.ͺॱ = null;
        }
    }

    private ByteBuffer ˎ(int i) {
        if (anr.ˋ >= 21) {
            return this.ʻॱ.getInputBuffer(i);
        }
        return this.ˋˋ[i];
    }

    private ByteBuffer ˋ(int i) {
        if (anr.ˋ >= 21) {
            return this.ʻॱ.getOutputBuffer(i);
        }
        return this.ͺॱ[i];
    }

    private boolean ˍ() {
        return this.ˏˎ >= 0;
    }

    private void ˋᐝ() {
        this.ˏˏ = -1;
        this.ʽ.ॱ = null;
    }

    private void ˋˋ() {
        this.ˏˎ = -1;
        this.ˎˏ = null;
    }

    private boolean ˎˎ() throws ExoPlaybackException {
        if (this.ʻॱ == null || this.ॱʼ == 2 || this.ᐧ) {
            return false;
        }
        if (this.ˏˏ < 0) {
            this.ˏˏ = this.ʻॱ.dequeueInputBuffer(0);
            if (this.ˏˏ < 0) {
                return false;
            }
            this.ʽ.ॱ = ˎ(this.ˏˏ);
            this.ʽ.ˊ();
        }
        if (this.ॱʼ == 1) {
            if (!this.ˋᐝ) {
                this.ᐝˋ = true;
                this.ʻॱ.queueInputBuffer(this.ˏˏ, 0, 0, 0, 4);
                ˋᐝ();
            }
            this.ॱʼ = 2;
            return false;
        } else if (this.ˍ) {
            this.ˍ = false;
            this.ʽ.ॱ.put(ˎ);
            this.ʻॱ.queueInputBuffer(this.ˏˏ, 0, ˎ.length, 0, 0);
            ˋᐝ();
            this.ॱʻ = true;
            return true;
        } else {
            int i;
            int i2;
            if (this.ᐨ) {
                i = -4;
                i2 = 0;
            } else {
                if (this.ـ == 1) {
                    for (i = 0; i < this.ॱˊ.ʼ.size(); i++) {
                        this.ʽ.ॱ.put((byte[]) this.ॱˊ.ʼ.get(i));
                    }
                    this.ـ = 2;
                }
                i2 = this.ʽ.ॱ.position();
                i = ˊ(this.ʻ, this.ʽ, false);
            }
            if (i == -3) {
                return false;
            }
            if (i == -5) {
                if (this.ـ == 2) {
                    this.ʽ.ˊ();
                    this.ـ = 1;
                }
                ˊ(this.ʻ.ॱ);
                return true;
            } else if (this.ʽ.ˏ()) {
                if (this.ـ == 2) {
                    this.ʽ.ˊ();
                    this.ـ = 1;
                }
                this.ᐧ = true;
                if (this.ॱʻ) {
                    try {
                        if (this.ˋᐝ) {
                            return false;
                        }
                        this.ᐝˋ = true;
                        this.ʻॱ.queueInputBuffer(this.ˏˏ, 0, 0, 0, 4);
                        ˋᐝ();
                        return false;
                    } catch (Exception e) {
                        throw ExoPlaybackException.ˊ(e, ॱᐝ());
                    }
                }
                ˏˏ();
                return false;
            } else if (!this.ᐝᐝ || this.ʽ.ˎ()) {
                this.ᐝᐝ = false;
                boolean ʻ = this.ʽ.ʻ();
                this.ᐨ = ॱ(ʻ);
                if (this.ᐨ) {
                    return false;
                }
                if (this.ˉ && !ʻ) {
                    and.ˊ(this.ʽ.ॱ);
                    if (this.ʽ.ॱ.position() == 0) {
                        return true;
                    }
                    this.ˉ = false;
                }
                try {
                    long j = this.ʽ.ˏ;
                    if (this.ʽ.i_()) {
                        this.ˋॱ.add(Long.valueOf(j));
                    }
                    if (this.ͺ != null) {
                        this.ʼ.ˋ(j, this.ͺ);
                        this.ͺ = null;
                    }
                    this.ʽ.ᐝ();
                    ˊ(this.ʽ);
                    if (ʻ) {
                        this.ʻॱ.queueSecureInputBuffer(this.ˏˏ, 0, ॱ(this.ʽ, i2), j, 0);
                    } else {
                        this.ʻॱ.queueInputBuffer(this.ˏˏ, 0, this.ʽ.ॱ.limit(), j, 0);
                    }
                    ˋᐝ();
                    this.ॱʻ = true;
                    this.ـ = 0;
                    acz o_acz = this.ˊ;
                    o_acz.ˋ++;
                    return true;
                } catch (Exception e2) {
                    throw ExoPlaybackException.ˊ(e2, ॱᐝ());
                }
            } else {
                this.ʽ.ˊ();
                if (this.ـ == 2) {
                    this.ـ = 1;
                }
                return true;
            }
        }
    }

    private boolean ॱ(boolean z) throws ExoPlaybackException {
        if (this.ॱˎ == null || (!z && this.ˏ)) {
            return false;
        }
        int ˋ = this.ॱˎ.ˋ();
        if (ˋ == 1) {
            throw ExoPlaybackException.ˊ(this.ॱˎ.ॱॱ(), ॱᐝ());
        } else if (ˋ == 4) {
            return false;
        } else {
            return true;
        }
    }

    protected void ˎ(String str, long j, long j2) {
    }

    protected void ˊ(Format format) throws ExoPlaybackException {
        boolean z;
        boolean z2 = false;
        Format format2 = this.ॱˊ;
        this.ॱˊ = format;
        this.ͺ = format;
        if (anr.ˎ(this.ॱˊ.ʻ, format2 == null ? null : format2.ʻ)) {
            z = false;
        } else {
            z = true;
        }
        if (z) {
            if (this.ॱˊ.ʻ == null) {
                this.ॱˋ = null;
            } else if (this.ˋ == null) {
                throw ExoPlaybackException.ˊ(new IllegalStateException("Media requires a DrmSessionManager"), ॱᐝ());
            } else {
                this.ॱˋ = this.ˋ.ˋ(Looper.myLooper(), this.ॱˊ.ʻ);
                if (this.ॱˋ == this.ॱˎ) {
                    this.ˋ.ˊ(this.ॱˋ);
                }
            }
        }
        if (this.ॱˋ == this.ॱˎ && this.ʻॱ != null) {
            switch (ॱ(this.ʻॱ, this.ʿ, format2, this.ॱˊ)) {
                case 0:
                    break;
                case 1:
                    z2 = true;
                    break;
                case 3:
                    if (!this.ˊᐝ) {
                        this.ॱʽ = true;
                        this.ـ = 1;
                        z = this.ˈ == 2 || (this.ˈ == 1 && this.ॱˊ.ͺ == format2.ͺ && this.ॱˊ.ˏॱ == format2.ˏॱ);
                        this.ˍ = z;
                        z2 = true;
                        break;
                    }
                    break;
                default:
                    throw new IllegalStateException();
            }
        }
        if (z2) {
            ˎˏ();
        } else {
            ˏˎ();
        }
    }

    protected void ˊ(MediaCodec mediaCodec, MediaFormat mediaFormat) throws ExoPlaybackException {
    }

    protected void ˊ(DecoderInputBuffer decoderInputBuffer) {
    }

    protected void ॱ(long j) {
    }

    protected int ॱ(MediaCodec mediaCodec, ahe o_ahe, Format format, Format format2) {
        return 0;
    }

    public boolean ʽॱ() {
        return this.ᐝˊ;
    }

    public boolean ˈ() {
        if (this.ॱˊ == null || this.ᐨ || (!ᐝॱ() && !ˍ() && (this.ˑ == -9223372036854775807L || SystemClock.elapsedRealtime() >= this.ˑ))) {
            return false;
        }
        return true;
    }

    protected long ˌ() {
        return 0;
    }

    protected float ˏ(float f, Format format, Format[] formatArr) {
        return SizeModifier.STABLE_STATE_SCALE;
    }

    private void ˎˏ() throws ExoPlaybackException {
        if (this.ॱˊ != null && anr.ˋ >= 23) {
            float ˏ = ˏ(this.ᐝॱ, this.ॱˊ, ʻॱ());
            if (this.ॱᐝ != ˏ) {
                this.ॱᐝ = ˏ;
                if (this.ʻॱ != null && this.ॱʼ == 0) {
                    if (ˏ == SizeModifier.STABLE_STATE_SCALE && this.ʼॱ) {
                        ˏˎ();
                    } else if (ˏ == SizeModifier.STABLE_STATE_SCALE) {
                    } else {
                        if (this.ʼॱ || ˏ > this.ॱॱ) {
                            Bundle bundle = new Bundle();
                            bundle.putFloat("operating-rate", ˏ);
                            this.ʻॱ.setParameters(bundle);
                            this.ʼॱ = true;
                        }
                    }
                }
            }
        }
    }

    private void ˏˎ() throws ExoPlaybackException {
        this.ʾ = null;
        if (this.ॱʻ) {
            this.ॱʼ = 1;
            return;
        }
        ˊˋ();
        ʼॱ();
    }

    private boolean ˋ(long j, long j2) throws ExoPlaybackException {
        if (!ˍ()) {
            int dequeueOutputBuffer;
            if (this.ˊˋ && this.ᐝˋ) {
                try {
                    dequeueOutputBuffer = this.ʻॱ.dequeueOutputBuffer(this.ˊॱ, ˌ());
                } catch (IllegalStateException e) {
                    ˏˏ();
                    if (this.ᐝˊ) {
                        ˊˋ();
                    }
                    return false;
                }
            }
            dequeueOutputBuffer = this.ʻॱ.dequeueOutputBuffer(this.ˊॱ, ˌ());
            if (dequeueOutputBuffer < 0) {
                if (dequeueOutputBuffer == -2) {
                    ͺॱ();
                    return true;
                } else if (dequeueOutputBuffer == -3) {
                    ˑ();
                    return true;
                } else {
                    if (this.ˋᐝ && (this.ᐧ || this.ॱʼ == 2)) {
                        ˏˏ();
                    }
                    return false;
                }
            } else if (this.ˌ) {
                this.ˌ = false;
                this.ʻॱ.releaseOutputBuffer(dequeueOutputBuffer, false);
                return true;
            } else if (this.ˊॱ.size != 0 || (this.ˊॱ.flags & 4) == 0) {
                this.ˏˎ = dequeueOutputBuffer;
                this.ˎˏ = ˋ(dequeueOutputBuffer);
                if (this.ˎˏ != null) {
                    this.ˎˏ.position(this.ˊॱ.offset);
                    this.ˎˏ.limit(this.ˊॱ.offset + this.ˊॱ.size);
                }
                this.ॱͺ = ˊ(this.ˊॱ.presentationTimeUs);
                ˏ(this.ˊॱ.presentationTimeUs);
            } else {
                ˏˏ();
                return false;
            }
        }
        if (this.ˊˋ && this.ᐝˋ) {
            try {
                boolean ˊ = ˊ(j, j2, this.ʻॱ, this.ˎˏ, this.ˏˎ, this.ˊॱ.flags, this.ˊॱ.presentationTimeUs, this.ॱͺ, this.ˏॱ);
            } catch (IllegalStateException e2) {
                ˏˏ();
                if (this.ᐝˊ) {
                    ˊˋ();
                }
                return false;
            }
        }
        ˊ = ˊ(j, j2, this.ʻॱ, this.ˎˏ, this.ˏˎ, this.ˊॱ.flags, this.ˊॱ.presentationTimeUs, this.ॱͺ, this.ˏॱ);
        if (ˊ) {
            ॱ(this.ˊॱ.presentationTimeUs);
            Object obj = (this.ˊॱ.flags & 4) != 0 ? 1 : null;
            ˋˋ();
            if (obj == null) {
                return true;
            }
            ˏˏ();
        }
        return false;
    }

    private void ͺॱ() throws ExoPlaybackException {
        MediaFormat outputFormat = this.ʻॱ.getOutputFormat();
        if (this.ˈ != 0 && outputFormat.getInteger("width") == 32 && outputFormat.getInteger("height") == 32) {
            this.ˌ = true;
            return;
        }
        if (this.ˎˎ) {
            outputFormat.setInteger("channel-count", 1);
        }
        ˊ(this.ʻॱ, outputFormat);
    }

    private void ˑ() {
        if (anr.ˋ < 21) {
            this.ͺॱ = this.ʻॱ.getOutputBuffers();
        }
    }

    protected void ʾ() throws ExoPlaybackException {
    }

    private void ˏˏ() throws ExoPlaybackException {
        if (this.ॱʼ == 2) {
            ˊˋ();
            ʼॱ();
            return;
        }
        this.ᐝˊ = true;
        ʾ();
    }

    private boolean ˊ(long j) {
        int size = this.ˋॱ.size();
        for (int i = 0; i < size; i++) {
            if (((Long) this.ˋॱ.get(i)).longValue() == j) {
                this.ˋॱ.remove(i);
                return true;
            }
        }
        return false;
    }

    private static CryptoInfo ॱ(DecoderInputBuffer decoderInputBuffer, int i) {
        CryptoInfo ˊ = decoderInputBuffer.ˋ.ˊ();
        if (i != 0) {
            if (ˊ.numBytesOfClearData == null) {
                ˊ.numBytesOfClearData = new int[1];
            }
            int[] iArr = ˊ.numBytesOfClearData;
            iArr[0] = iArr[0] + i;
        }
        return ˊ;
    }

    private boolean ـ() {
        return "Amazon".equals(anr.ˏ) && ("AFTM".equals(anr.ˊ) || "AFTB".equals(anr.ˊ));
    }

    private static boolean ˎ(String str) {
        return anr.ˋ < 18 || ((anr.ˋ == 18 && ("OMX.SEC.avc.dec".equals(str) || "OMX.SEC.avc.dec.secure".equals(str))) || (anr.ˋ == 19 && anr.ˊ.startsWith("SM-G800") && ("OMX.Exynos.avc.dec".equals(str) || "OMX.Exynos.avc.dec.secure".equals(str))));
    }

    private int ˏ(String str) {
        if (anr.ˋ <= 25 && "OMX.Exynos.avc.dec.secure".equals(str) && (anr.ˊ.startsWith("SM-T585") || anr.ˊ.startsWith("SM-A510") || anr.ˊ.startsWith("SM-A520") || anr.ˊ.startsWith("SM-J700"))) {
            return 2;
        }
        if (anr.ˋ >= 24 || ((!"OMX.Nvidia.h264.decode".equals(str) && !"OMX.Nvidia.h264.decode.secure".equals(str)) || (!"flounder".equals(anr.ˎ) && !"flounder_lte".equals(anr.ˎ) && !"grouper".equals(anr.ˎ) && !"tilapia".equals(anr.ˎ)))) {
            return 0;
        }
        return 1;
    }

    private static boolean ˋ(String str) {
        return anr.ˊ.startsWith("SM-T230") && "OMX.MARVELL.VIDEO.HW.CODA7542DECODER".equals(str);
    }

    private static boolean ˋ(String str, Format format) {
        return anr.ˋ < 21 && format.ʼ.isEmpty() && "OMX.MTK.VIDEO.DECODER.AVC".equals(str);
    }

    private static boolean ˊ(ahe o_ahe) {
        String str = o_ahe.ˎ;
        return (anr.ˋ <= 17 && ("OMX.rk.video_decoder.avc".equals(str) || "OMX.allwinner.video.decoder.avc".equals(str))) || ("Amazon".equals(anr.ˏ) && "AFTS".equals(anr.ˊ) && o_ahe.ʽ);
    }

    private static boolean ॱ(String str) {
        return (anr.ˋ <= 23 && "OMX.google.vorbis.decoder".equals(str)) || (anr.ˋ <= 19 && (("hb2000".equals(anr.ˎ) || "stvm8".equals(anr.ˎ)) && ("OMX.amlogic.avc.decoder.awesome".equals(str) || "OMX.amlogic.avc.decoder.awesome.secure".equals(str))));
    }

    private static boolean ˊ(String str) {
        return anr.ˋ == 21 && "OMX.google.aac.decoder".equals(str);
    }

    private static boolean ˎ(String str, Format format) {
        if (anr.ˋ <= 18 && format.ॱˎ == 1 && "OMX.MTK.AUDIO.DECODER.MP3".equals(str)) {
            return true;
        }
        return false;
    }
}
